set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode='nonstrict';
set hive.exec.max.dynamic.partitions=400;
set hive.exec.max.dynamic.partitions.pernode=400;


insert overwrite table jms_dm.dm_send_warning_summary_dt
select
    first_center_agent_code as first_center_agent_code --始发转运中心所属代理区编码
     ,first_center_agent_name as first_center_agent_name --始发转运中心名称代理区名称
     ,first_center_code       as first_center_code       --始发转运中心编码
     ,first_center_name       as first_center_name       --始发转运中心名称
     ,registr_scan_site_code  as registr_scan_site_code  --登记网点编码
     ,registr_scan_site_name  as registr_scan_site_name  --登记网点名称
     ,bagg_scan_site_code     as bagg_scan_site_code     --登记环节/建包网点编码
     ,bagg_scan_site_name     as bagg_scan_site_name     --登记环节/建包网点名称
     ,count(case when package_code is null then waybill_no end) as send_cnt  --单件有发未到量
     ,count(case when package_code is not null then waybill_no end) as pack_cnt --包件有发未到量   
     ,count(case when package_code is null then waybill_no end) + count(case when package_code is not null then waybill_no end) as send_tot --有发未到总量   
     ,count(case when if_arr = 1 and package_code is null then waybill_no end) as send_ref_cnt --单件重刷量   
     ,count(case when if_arr = 1 and package_code is not null then package_code end) as pack_ref_cnt --包件重刷量   
     ,dt
from jms_dm.dm_send_warning_detail_dt
where dt between date_sub('{{ execution_date | cst_ds }}',7) and '{{ execution_date | cst_ds }}'
group by first_center_agent_code
       ,first_center_agent_name
       ,first_center_code
       ,first_center_name
       ,bagg_scan_site_code
       ,bagg_scan_site_name
       ,registr_scan_site_code
       ,registr_scan_site_name
       ,dt
distribute by dt,pmod(hash(rand()),1);